package com.birdpiss.commons.manager;

import javax.annotation.PostConstruct;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.birdpiss.commons.dao.interfaces.TransactionDao;
import com.birdpiss.commons.domain.Transaction;
import com.birdpiss.commons.manager.interfaces.TransactionManager;

/**
 * The Class DefaultTransactionManager.
 *
 * @author mark
 */
@Service("transactionManager")
public class DefaultTransactionManager implements TransactionManager {

	private static final Logger log = Logger.getLogger(TransactionManager.class);
	private TransactionDao transactionDao;

	/**
	 * Verify DI was setup correctly and perform any post DI initialization.
	 */
	@PostConstruct
	public void initialize() {
		if (this.transactionDao == null) throw new BeanCreationException("Must set Transaction Dao");
	}

	/* (non-Javadoc)
	 * @see com.birdpiss.commons.manager.interfaces.TransactionManager#getTransactionById(java.lang.Integer)
	 */
	@Override
	public Transaction getTransactionById(Integer transactionId) {
		return this.transactionDao.getTransactionById(transactionId);
	}

	/* (non-Javadoc)
	 * @see com.birdpiss.commons.manager.interfaces.TransactionManager#insertTransaction(com.birdpiss.commons.domain.Transaction)
	 */
	@Override
	public Transaction insertTransaction(Transaction transaction) {
		return this.transactionDao.insertTransaction(transaction);
	}

	/**
	 * Sets the transaction dao.
	 *
	 * @param transactionDao the new transaction dao
	 */
	@Autowired
	public void setTransactionDao(TransactionDao transactionDao) {
		this.transactionDao = transactionDao;
	}

}
